package com.lottery.ruok.lottrey.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.adapter.CommonFragmentStatePagerAdapter;
import com.lottery.ruok.lottrey.fragment.BaseFragment;
import com.lottery.ruok.lottrey.fragment.ChildActivitiesListFragment;
import com.lottery.ruok.lottrey.retrofitModule.response.ActivityListResponse;
import com.lottery.ruok.lottrey.ui.ShapeIndicatorView;
import com.ogaclejapan.smarttablayout.SmartTabLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ActivitiesCenterActivity extends BaseActivity {

    @BindView(R.id.viewpagertab)
    SmartTabLayout tabLayout;
    @BindView(R.id.vpview)
    ViewPager vpView;
    private CommonFragmentStatePagerAdapter adapter;
    private String[] mTitles = {"热门", "可参与", "完成中", "已完成", "全部"};
    private String[] status = {"100", "101", "2", "102", "all"};

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_activities_center_layout);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        //initViewpage
        final List<BaseFragment> fragments = new ArrayList<>();
        List<String> titles = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            ChildActivitiesListFragment childActivitiesListFragment = new ChildActivitiesListFragment();
            Bundle bundle = new Bundle();
            bundle.putString("status", status[i]);
            childActivitiesListFragment.setArguments(bundle);
            fragments.add(childActivitiesListFragment);
            titles.add(mTitles[i]);
        }
        adapter = new CommonFragmentStatePagerAdapter(getSupportFragmentManager(), fragments, titles);

        vpView.setAdapter(adapter);

        vpView.setOffscreenPageLimit(5);
        vpView.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                fragments.get(position).setSwipState();
            }

            @Override
            public void onPageScrollStateChanged(int state) {
            }
        });

        SmartTabLayout viewPagerTab = findViewById(R.id.viewpagertab);
        viewPagerTab.setViewPager(vpView);
    }

    @OnClick({R.id.rl_back})
    public void onViewClicked(View view) {
        switch (view.getId()){
            case R.id.rl_back:
                finish();
                break;
        }
    }


    @Override
    protected void onResume() {
        super.onResume();
    }

}
